/**
 * User: Oleksii Savchenko
 * Date: 22.02.13
 * Time: 11:49
 */
describe('Main actions for Item list ',function(){

    describe('Can open popup window', function(){
        beforeEach (function(){
            this.clock = sinon.useFakeTimers();
            this.elem = document.createElement("div");
            this.elem.setAttribute("id", "elementId");
            this.elem.setAttribute("data-id", "elem_1");
            document.getElementsByTagName("body")[0].appendChild(this.elem);
        });
        afterEach (function(){
            document.getElementsByTagName("body")[0].removeChild(this.elem);
        });

        it('should set id and set display block', function(){
            this.elem.setAttribute("style", "display: none");
            var appActions = Object.create(mainActions);

            var styleNone = window.getComputedStyle(this.elem, "");
            var displayNone = styleNone.getPropertyValue("display");
            expect(displayNone).toBe('none');

            appActions.openPopup('#elementId', this.elem);

            this.clock.tick(150);
            var styleBlock = window.getComputedStyle(this.elem, "");
            var displayBlock = styleBlock.getPropertyValue("display");

            expect(appActions._id).toBe('elem_1');
            expect(appActions._selector).toBe('#elementId');
            expect(displayBlock).toBe('block');
        });
    });

    describe('Can hede popup window', function(){
        beforeEach (function(){
            this.clock = sinon.useFakeTimers();
            this.elem = document.createElement("div");
            this.elem.setAttribute("id", "elementId");
            document.getElementsByTagName("body")[0].appendChild(this.elem);
        });
        afterEach (function(){
            document.getElementsByTagName("body")[0].removeChild(this.elem);
        });

        it('should hide popup window', function(){
            var appActions = Object.create(mainActions);

            var styleBlock = window.getComputedStyle(this.elem, "");
            var displayBlock = styleBlock.getPropertyValue("display");
            expect(displayBlock).toBe('block');
            appActions.closePopup('#elementId');

            this.clock.tick(200);
            var styleNone = window.getComputedStyle(this.elem, "");
            var displayNone = styleNone.getPropertyValue("display");
            expect(displayNone).toBe('none');
        });
    });

    describe('Can add item', function(){
        beforeEach (function(){
            this.elem = document.createElement("div");
            this.elem.setAttribute("id", "elementId");
            document.getElementsByTagName("body")[0].appendChild(this.elem);
        });
        afterEach (function(){
            document.getElementsByTagName("body")[0].removeChild(this.elem);
        });

        it('should set item content', function(){
            var appActions = Object.create(mainActions);
            var stub = sinon.stub(appActions, '_setNewItem');

            appActions.addItem('#elementId');
            expect(stub).toHaveBeenCalled();
        });
    });

});